package com.coship.vas.dapg.util;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
/**
 * 缓存工具类
 * @author 904912
 *
 */
public class SysCacheUtil {
    private static Cache cache = null;

    public static Cache getCache(String cacheName) {
        CacheManager manager = CacheManager.getInstance();
        cache = manager.getCache(cacheName);
        if (cache == null) {
            manager.addCache(cacheName);
            cache = manager.getCache(cacheName);
        }
        return cache;
    }

    public static Element get(Object key) {
        return cache.get(key);
    }

    public static Element set(Object key, Object value) {
        Element e = new Element(key, value);
        cache.put(e);
        return e;
    }

    public static void removeAll() {
        cache.removeAll();
    }

    public static void remove(Object key) {
        cache.remove(key);
    }
}
